# PowerShell script to compile fixed go-agent
Write-Host "=== 编译修复后的go-agent ===" -ForegroundColor Green
Write-Host ""

# 设置环境变量
$env:GOCACHE = "$PWD\.temp_cache"
$env:GOMODCACHE = "$PWD\.temp_modcache"  
$env:GOPROXY = "direct"
$env:GOSUMDB = "off"

# 创建缓存目录
New-Item -ItemType Directory -Force -Path ".temp_cache" | Out-Null
New-Item -ItemType Directory -Force -Path ".temp_modcache" | Out-Null

Write-Host "环境变量设置:" -ForegroundColor Yellow
Write-Host "GOCACHE: $env:GOCACHE"
Write-Host "GOMODCACHE: $env:GOMODCACHE"
Write-Host "GOPROXY: $env:GOPROXY"
Write-Host ""

Write-Host "开始编译修复后的程序..." -ForegroundColor Yellow
Write-Host "修复内容: JSON字段映射 itemkey->itemKey, updateIntervalseconds->updateIntervalSeconds"
Write-Host ""

try {
    go build -o go-agent-fixed.exe cmd/agent/main.go
    if ($LASTEXITCODE -eq 0) {
        Write-Host "✅ 编译成功！" -ForegroundColor Green
        Write-Host "生成文件: go-agent-fixed.exe"
        Write-Host ""
        Write-Host "修复说明:" -ForegroundColor Cyan
        Write-Host "- 修复了JSON字段映射问题"  
        Write-Host "- 现在可以正确解析API返回的配置"
        Write-Host "- 动态调度器应该能正常启动"
        Write-Host "- 各监控项将按配置的间隔上报:"
        Write-Host "  • CPU使用率: 40秒"
        Write-Host "  • CPU核心数: 50秒"  
        Write-Host "  • 内存总量: 60秒"
        Write-Host "  • 内存使用率: 30秒"
        Write-Host "  • 主机名: 30秒+时间窗口"
        Write-Host ""
        Write-Host "运行修复版本: .\go-agent-fixed.exe -v" -ForegroundColor Green
    } else {
        Write-Host "❌ 编译失败！" -ForegroundColor Red
    }
} catch {
    Write-Host "❌ 编译过程中发生错误: $_" -ForegroundColor Red
}

Write-Host ""
Write-Host "按任意键继续..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")